﻿/// <reference path="vswd-ext_2.2.js" />

//*********this window let the client set user define timezone***************/

///Modified 2010-9 

Ext.ms02data.timezone = [
    ['-720','GMT-12:00'],
    ['-660','GMT-11:00'],
    ['-600','GMT-10:00'],
    ['-540','GMT-09:00'],
    ['-480','GMT-08:00'],
    ['-420','GMT-07:00'],
    ['-360','GMT-06:00'],
    ['-300', 'GMT-05:00'],
    ['-270', 'GMT-04:30'],
    ['-240','GMT-04:00'],
    ['-180','GMT-03:00'],
    ['-120','GMT-02:00'],
    ['-60','GMT-01:00'],
    ['0','GMT'],
    ['60','GMT+01:00'],
    ['120','GMT+02:00'],
    ['180','GMT+03:00'],
    ['210','GMT+03:30'],
    ['240','GMT+04:00'],
    ['270','GMT+04:30'],
    ['300','GMT+05:00'],
    ['330','GMT+05:30'],
    ['345','GMT+05:45'],
    ['360','GMT+06:00'],
    ['390','GMT+06:30'],
    ['420','GMT+07:00'],
    ['480','GMT+08:00'],
    ['540','GMT+09:00'],
    ['570','GMT+09:30'],
    ['600', 'GMT+10:00'],
    ['630', 'GMT+10:30'],
    ['660', 'GMT+11:00'],
    ['720', 'GMT+12:00'],
    ['780', 'GMT+13:00']
];

Ext.ms02data.MeiMapType = [
    ['0', _TrackerMain_GoogleMap],
    ['1', _TrackerMain_BingMap]
];

//if (typeof(showMapABC) != 'undefined'){
//    if (showMapABC)
//        Ext.ms02data.MeiMapType.push(['2', 'MapABC']);
//}


if(typeof(showGoogleV3) != 'undefined'){
    if(showGoogleV3)
        Ext.ms02data.MeiMapType.push(['3', 'Google V3']);
}

if(typeof(showOSM) != 'undefined'){
    if(showOSM)
        Ext.ms02data.MeiMapType.push(['4', 'OSM']);
}

//get time zone
function gettimezone(){
    var now = new Date();
    return now.getTimezoneOffset();
}

function showSettingsWindow() {

    var timezonestore = new Ext.data.ArrayStore({
        fields: ['minutevalue', 'GMTZone'],
        data: Ext.ms02data.timezone
    });

    var maptypestore = new Ext.data.ArrayStore({
        fields: ['val', 'des'],
        data: Ext.ms02data.MeiMapType
    });

    var cmbMapType = new Ext.form.ComboBox({
        editable: false,
        labelStyle: 'padding-top:6px;padding-left:10px;text-align:left;width:150',
        fieldLabel: _TrackerMain_MapType,
        store: maptypestore,
        valueField: 'val',
        displayField: 'des',
        typeAhead: false,
        mode: 'local',
        forceSelection: true,
        triggerAction: 'all',
        emptyText: '',
        selectOnFocus: true,
        width: 170
    });

    cmbMapType.setValue(meimaptype);
    
    var cmbTimezone = new Ext.form.ComboBox({
        editable: false,
        labelStyle: 'padding-top:6px;padding-left:10px;text-align:left;width:150',
        fieldLabel: _TrackerMain_ChooseTimeZone,
        store: timezonestore,
        valueField: 'minutevalue',
        displayField: 'GMTZone',
        typeAhead: false,
        mode: 'local',
        forceSelection: true,
        triggerAction: 'all',
        emptyText: '',
        selectOnFocus: true,
        width:170
    });

     
    var chkCloseAlarmSound = new Ext.form.Checkbox({
        labelStyle: 'padding-top:6px;padding-left:10px;text-align:left;width:150',
        fieldLabel: _TrackerMain_TurnOffAlarmSound,
        checked:  turnoffalarmsound
    });

    var chkOnlyShowSelectedDevice = new Ext.form.Checkbox({
        labelStyle: 'padding-top:6px;padding-left:10px;text-align:left;width:150',
        fieldLabel: _TrackerMain_OnlyShowSelected,
        checked: onlyshowselecteddevice
    });
    
    var chkUnitShowMiles = new Ext.form.Checkbox({
        labelStyle:'padding-top:6px;padding-left:10px;text-align:left;width:150',
        fieldLabel:_TrackerMain_Miles,
        checked:showmiles
    });
    
    var chkFahrenheit = new Ext.form.Checkbox({
        labelStyle:'padding-top:6px;padding-left:10px;text-align:left;width:150',
        fieldLabel:_TrackerMain_Fahrenheit,
        checked:showfahrenheit
    });
    
    chkCloseAlarmSound.setValue(turnoffalarmsound);
    
    var win = new Ext.Window({
        title: _TrackerMain_SystemSettings,
        width: 400,
        height: 300,
        layout: "form",
        bodyStyle: 'padding-top:6px',
        items: [cmbMapType, cmbTimezone, chkCloseAlarmSound, chkUnitShowMiles, chkOnlyShowSelectedDevice,chkFahrenheit],
        buttons: [{
            text: _TrackerMain_Save,
            handler: function() {
                turnoffalarmsound = chkCloseAlarmSound.checked;
                setCookie('turnoffalarmsound', turnoffalarmsound, 365);
                setCookie('meimaptype', cmbMapType.getValue(), 365);
                setCookie('onlyshowselected', chkOnlyShowSelectedDevice.getValue(), 365);
                setCookie('showmiles', chkUnitShowMiles.getValue(), 365);
                setCookie('showfahrenheit',chkFahrenheit.getValue(),365);
                Ext.Ajax.request({
                    url: 'HandlerChangeTimeZone',
                    method: 'post',
                    params: {
                        timezone: cmbTimezone.getValue()
                    },
                    success: function(btn) {
                        var val = btn.responseText;
                        if (val == 0) {

                        }
                        else {
                            setCookie('gpstimezone', cmbTimezone.getValue(), 365);
                            window.location.href = val;
                        }
                    }
                });
            } }]
        })

        var tt = getCookie("gpstimezone");
        var timezoneminutes;
        if (tt == null)
            timezoneminutes = -gettimezone();
        else
            timezoneminutes = parseInt(tt);
        cmbTimezone.setValue(timezoneminutes);
        win.show();
    }


